package com.yoyo.itravel.dao;

import com.yoyo.itravel.bean.SightTheme;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description 景点主题相关操作持久层接口
 * @Author HZX
 * @Version 1.0
 * @Date 2020/6/26 11:31
 */
@Repository
public interface ISightThemeDao {

    /**
     * @Description 插入景点主题
     *
     * @param theme
     * @return int
     */

    @Insert("insert into tb_sight_theme(themeId, themeName, description) values(#{theme.themeId},#{theme.themeName},#{theme.description})")
    int insert(SightTheme theme) throws SQLException;

    /**
     * @Description 通过景点id删除景点主题
     *
     * @param themeId
     * @return int
     */
    @Delete("delete from tb_sight_theme where themeId=#{themeId}")
    int deleteById(String themeId) throws SQLException;

    /**
     * @Description 通过景点id查询景点主题
     *
     * @param themeId
     * @return int
     */
    @Select("select * from tb_sight_theme where themeId=#{themeId}")
    SightTheme selectById(String themeId) throws SQLException;

    /**
     * @Description 通过景点名称查询景点主题
     *
     * @param themeName
     * @return int
     */
    @Select("select * from tb_sight_theme where themeName=#{themeName}")
    SightTheme selectByName(String themeName) throws SQLException;

    /**
     * @Description 查找所有的景点主题
     *
     * @param
     * @return java.util.List<cn.hut.travel.bean.SightTheme>
     */
    @Select("select * from tb_sight_theme")
    List<SightTheme> selectAll() throws SQLException;

    /**
     * @Description 通过景点id查找该景点所有的主题
     *
     * @param sightId
     * @return java.util.List<cn.hut.travel.bean.SightTheme>
     */
    @Select("select t.* from middle_tb_sight_theme s_t join tb_sight s on s_t.sightId=s.sightId and s.sightId=#{sightId} join tb_sight_theme t on t.themeId=s_t.themeId")
    List<SightTheme> selectAllBySightId(String sightId) throws SQLException;
}
